import Abstract from '../abstract';
import type {Login, Register} from '../types';

class AuthUser extends Abstract {
    Login(data: Login) {
        return this.postReq({url: 'Login.login', data});
    }

    Register(data: Register) {
        return this.postReq({url: 'Login.register', data});
    }

    SendEmail(data: { email: string }) {
        return this.getReq({url: 'Login.send_email', params: data});
    }

    UpdateUser(data: { avatar?: string; username?: string }) {
        return this.postReq({url: 'Users.update_user', data});
    }

    GetOss() {
        return this.getReq({url: 'Basic.oss'});
    }

    UserInfo() {
        return this.getReq({url: 'Basic.user_info'});
    }
}

// 单列模式返回对象
let instance;
export default (() => {
    if (instance) return instance;
    instance = new AuthUser();
    return instance;
})();
